package com.wanglei.rdd.action

import org.apache.spark.{SparkConf, SparkContext}

object Spark02_reduce {

  def main(args: Array[String]): Unit = {

    //
    val conf = new SparkConf().setMaster("local[2]").setAppName("map")
    val sc = new SparkContext(conf)


    val rdd = sc.makeRDD(List(
      1, 2, 3, 4
    ))

    // reduce
    val res = rdd.reduce(_ + _)
    println(res)


    // count
    val cnt = rdd.count()
    println(cnt)

    // first
    val first = rdd.first()
    println(first)

    // take
    val take = rdd.take(3)
    println(take.mkString(","))

    //
    val res1 = rdd.takeOrdered(2)
    println(res1.mkString(","))

    sc.stop()

  }

}


